package train1;

import java.util.Scanner;

public class Demo {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请先输入学生数量：");
		int num = scanner.nextInt();
		Student[] students = new Student[num];
		for(int i = 0; i < students.length; i++) {
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的姓名：");
			String name = scanner.next();
			System.out.println("请输入学生的班级：");
			String className = scanner.next();
			Student student = new Student(id, age, name, className);
			students[i] = student;
			
		}
		for(int i = 0; i < students.length; i++) {
			Student student = students[i];//拿出来
			System.out.println(student);
		
			student.show();
			
		}
		
		System.out.println("-----------------------");
		while(true) {
			System.out.println("按照id查找输入1：");
			System.out.println("按照年龄查找输入2：");
			System.out.println("按照姓名查找输入3");
			System.out.println("按照班级查找输入4");
			System.out.println("退出输入0：");
		
			int type = scanner.nextInt();
			if(type == 0) {
				System.out.println("退出");
				break;
			}
			switch(type) {
			case 1:
				System.out.println("请输入需要查找的id：");
				int id = scanner.nextInt();
				boolean isExistId = false;
				for(int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (student.getId() == id) {
						isExistId = true;
						System.out.println(student);
					}
					
					
				}
				if (isExistId == false) {
					System.out.println("查无此人");

				}
				break;
			case 2:
				System.out.println("请输入需要查找的age：");
				int age = scanner.nextInt();
				boolean isExistAge = false;
				for(int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (student.getAge() == age) {
						isExistAge = true;
						System.out.println(student);
					}
					
					
				}
				if (isExistAge == false) {
					System.out.println("查无此人");

				}
				break;
			case 3:
				System.out.println("请输入需要查找的name：");
				String name = scanner.next();
				boolean isExistName = false;
				for(int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (name.equals(student.getName())) {
						isExistName = true;
						System.out.println(student);
					}
					
					
				}
				if (isExistName == false) {
					System.out.println("查无此人");

				}
				break;
			case 4:
				System.out.println("请输入需要查找的className：");
				String className = scanner.next();
				boolean isExistClassName = false;
				for(int i = 0; i < students.length; i++) {
					Student student = students[i];
					if (className.equals(student.getClassName())) {
						isExistClassName = true;
						System.out.println(student);
					}
					
					
				}
				if (isExistClassName == false) {
					System.out.println("查无此人");

				}
				break;
			default:
				break;
		}
		
		}
	}

}
